<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class HelpWorkOrder extends Model
{
    protected $fillable = [
        'object_id',
        'object_type',
        'content',
        'images',
        'user_id',
        'role',
        'p_id',
    ];

    protected $guarded = [];

    protected $casts = [
        'images' => 'json',
    ];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->withDefault();
    }

    public function reply()
    {
        return $this->hasMany(HelpWorkOrder::class, 'p_id')->orderBy('id');
    }

    public static $CLOSED_MAP = [
        '正常', '關閉',
    ];

    public function shop()
    {
        return $this->belongsTo(Shop::class)->withDefault();
    }

    public function object()
    {
        return $this->morphTo();
    }
}
